<?php

namespace App\Repositories\Eloquent;

use App\Models\PolicyProductMark;
use App\Repositories\Contracts\PolicyProductMarkInterface;
use MakeRep\Repository;

class PolicyProductMarkRepository extends Repository implements PolicyProductMarkInterface
{

    function model()
    {
        return PolicyProductMark::class;
    }

    /**
     * 添加产品类型
     * @param $data
     * @param $policyId
     * @return mixed
     */
    public function create($data,$policyId){

        $this->delete(['policy_id'=>$policyId]);

        if (!empty($data['product_mark'])) {

            $createdAt = date('Y-m-d H:i:s');
            $addData = [];
            foreach ($data['product_mark'] as $value){

                $addData[] = [
                    'product_mark'  => $value,
                    'policy_id'     => $policyId,
                    'created_at'    => $createdAt,
                    'updated_at'    => $createdAt,
                ];
            }

            $this->insert($addData);
        }
    }
}